package java_thinking.unit_18_IO._18_1;

import java.io.File;

/**
 * @Desc:
 * @author: cww
 * @DateTime: 2019/5/13 8:34
 */

public class MakeDirectories {
    private static void usage() {
        System.err.println(
                "Usage:MakerDirectories path1 ...\n" +
                "Creates each path\n" +
                "Usage:MakeDirectories -d path1 ...\n" +
                "Deletes each path\n" +
                "Usage:MakeDirectories -r path1 path2\n" +
                "Renames from path1 to path2");
        System.exit(1);
    }
    private static void fileData(File f) {
        System.out.println(
                "Absolute path: " + f.getAbsolutePath() +
                        "\n Can read: " + f.canRead() +
                        "\n Can write: " + f.canWrite() +
                        "\n getName: " + f.getName() +
                        "\n getParent: " + f.getParent() +
                        "\n length: " + f.length() +
                        "\n lastModified: " + f.lastModified());
        if (f.isFile()) {
            System.out.println("It's a file");
        }else if (f.isDirectory()) {
            System.out.println("It's a directory");
        }
    }

    public static void main(String[] args) {
        String[] str = {"-r","cache1","cache"};
        if (str[0].equals("-r")) {
            if (str.length != 3) {
                usage();
            }
            File old = new File(str[1]),
                    rname = new File(str[2]);
            old.renameTo(rname);
            fileData(old);
            fileData(rname);
            return;
        }
    }
}
